home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / share / src / gnu / unexelfsgi.c.patch.z / unexelfsgi.c.patch
Encoding:
Text File  |  1994-08-02  |  4.2 KB  |  129 lines

  1. Newsgroups: comp.sys.sgi.apps
  2. From: davea@quasar.mti.sgi.com (David B.Anderson)
  3. Subject: emacs 19.22 unexelfsgi.c patch allows dbx use
  4. Organization: Silicon Graphics, Inc.  Mountain View, CA
  5. Date: Mon, 17 Jan 1994 21:49:43 GMT
  6.  
  7. The following is a context diff of a patch to 
  8. unexelfsgi.c.  This allows use of dbx or WorkShop on the
  9. unexec'd emacs image.    The problem was wierdness in the
  10. mdebug section requiring addition of some sgi-specific code.
  11.  
  12. *** unexelfsgi.c    1994/01/16 21:54:40 old
  13. --- unexelfsgi.c    1994/01/17 21:33:19 new
  14. ***************
  15. *** 418,423 ****
  16. --- 418,424 ----
  17.   #include <unistd.h>
  18.   #include <fcntl.h>
  19.   #include <elf.h>
  20. + #include <syms.h> /* for HDRR declaration */
  21.   #include <sys/mman.h>
  22.   
  23.   #ifndef emacs
  24. ***************
  25. *** 493,498 ****
  26. --- 494,500 ----
  27.     Elf32_Addr new_data2_addr;
  28.   
  29.     int n, nn, old_bss_index, old_data_index, new_data2_index;
  30. +   int old_mdebug_index;
  31.     struct stat stat_buf;
  32.   
  33.     /* Open the old file & map it into the address space. */
  34. ***************
  35. *** 523,528 ****
  36. --- 525,545 ----
  37.     old_section_names = (char *) old_base
  38.       + OLD_SECTION_H(old_file_h->e_shstrndx).sh_offset;
  39.   
  40. +   /* Find the mdebug section, if any
  41. +    */
  42. +   for (old_mdebug_index = 1; old_mdebug_index < old_file_h->e_shnum; old_mdebug_index++)
  43. +     {
  44. + #ifdef DEBUG
  45. +       fprintf (stderr, "Looking for .mdebug - found %s\n",
  46. +            old_section_names + OLD_SECTION_H(old_mdebug_index).sh_name);
  47. + #endif
  48. +       if (!strcmp (old_section_names + OLD_SECTION_H(old_mdebug_index).sh_name,
  49. +            ".mdebug"))
  50. +     break;
  51. +     }
  52. +   if (old_mdebug_index == old_file_h->e_shnum)
  53. +     old_mdebug_index = -1; /* just means no such section was present */
  54.     /* Find the old .bss section.  Figure out parameters of the new
  55.      * data2 and bss sections.
  56.      */
  57. ***************
  58. *** 748,753 ****
  59. --- 765,819 ----
  60.         
  61.         memcpy (NEW_SECTION_H(nn).sh_offset + new_base, src,
  62.             NEW_SECTION_H(nn).sh_size);
  63. +       /* Adjust  the HDRR offsets in .mdebug and copy the 
  64. +        * line data if it's in its usual 'hole' in the object.
  65. +        * Makes the new file debuggable with dbx.
  66. +        * patches up two problems: the absolute file offsets
  67. +        * in the HDRR record of .mdebug (see /usr/include/syms.h), and
  68. +        * the ld(1) bug that gets the line table in a hole in the
  69. +        * elf file rather than in the .mdebug section proper.
  70. +        * David Anderson. davea@sgi.com  Jan 16,1994
  71. +        */
  72. +       if(n == old_mdebug_index) {
  73. + #define MDEBUGADJUST(__ct,__fileaddr) \
  74. + if(n_phdrr->__ct > 0) { \
  75. +     n_phdrr->__fileaddr += movement; \
  76. + }
  77. +     HDRR * o_phdrr = (HDRR *)((byte *)old_base + OLD_SECTION_H(n).sh_offset);
  78. +     HDRR * n_phdrr = (HDRR *)((byte *)new_base + NEW_SECTION_H(nn).sh_offset);
  79. +     unsigned movement = new_data2_size;
  80. +     MDEBUGADJUST(idnMax,cbDnOffset);
  81. +     MDEBUGADJUST(ipdMax,cbPdOffset);
  82. +     MDEBUGADJUST(isymMax,cbSymOffset);
  83. +     MDEBUGADJUST(ioptMax,cbOptOffset);
  84. +     MDEBUGADJUST(iauxMax,cbAuxOffset);
  85. +     MDEBUGADJUST(issMax,cbSsOffset);
  86. +     MDEBUGADJUST(issExtMax,cbSsExtOffset);
  87. +     MDEBUGADJUST(ifdMax,cbFdOffset);
  88. +     MDEBUGADJUST(crfd,cbRfdOffset);
  89. +     MDEBUGADJUST(iextMax,cbExtOffset);
  90. +     /* The Line Section, being possible off in a hole of the object,
  91. +      * requires special handling
  92. +      */
  93. +     if(n_phdrr->cbLine > 0) {
  94. +       if(o_phdrr->cbLineOffset > (OLD_SECTION_H(n).sh_offset +
  95. +             OLD_SECTION_H(n).sh_size)) {
  96. +         /* line data is in a hole in elf. do special copy and adjust
  97. +                for this ld mistake.
  98. +          */
  99. +         n_phdrr->cbLineOffset += movement;
  100. +         memcpy(n_phdrr->cbLineOffset + new_base,
  101. +                o_phdrr->cbLineOffset + old_base, n_phdrr->cbLine);
  102. +       } else {
  103. +         /* somehow line data is in .mdebug as it is supposed to be!! ??
  104. +          */
  105. +         MDEBUGADJUST(cbLine,cbLineOffset);
  106. +       }
  107. +     }
  108. +       }
  109.   
  110.         /* If it is the symbol table, its st_shndx field needs to be patched. */
  111.         if (NEW_SECTION_H(nn).sh_type == SHT_SYMTAB
  112.  
  113.  
  114.  
  115.  
  116. This has received minimal testing, but does appear to work.
  117. Your milage may vary.  No warrantees. 
  118.  
  119. Enjoy!
  120. [ David B. Anderson             (415)390-4263             davea@sgi.com ]
  121. [                      Visualize  Whirled Peas                          ]
  122.  
  123.  
  124.  
  125.